package com.ethan.dynamicproxy;

import com.google.common.base.Stopwatch;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;

/**
 * @author ethan
 * create 2018-08-02 上午11:06
 * desc 动态代理对应的调用处理程序类
 **/
public class SubjectInvocationHandler implements InvocationHandler {
    //代理类持有一个委托类的对象引用
    private Object delegate;

    public SubjectInvocationHandler(Object delegate){
        this.delegate = delegate;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Stopwatch stopwatch = Stopwatch.createStarted();
        method.invoke(delegate,args);
        System.out.printf("执行任务耗时ddd"+stopwatch.elapsed(TimeUnit.MILLISECONDS));
        return null;
    }

}
